package com.ruoyi.erp.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.erp.domain.LedyUserClient;
import com.ruoyi.erp.service.ILedyUserClientService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 案件当事人Controller
 * 
 * @author ztj
 * @date 2023-04-04
 */
@RestController
@RequestMapping("/erp/client")
public class LedyUserClientController extends BaseController
{
    @Autowired
    private ILedyUserClientService ledyUserClientService;

    /**
     * 查询案件当事人列表
     */
    @PreAuthorize("@ss.hasPermi('erp:client:list')")
    @GetMapping("/list")
    public TableDataInfo list(LedyUserClient ledyUserClient)
    {
        startPage();
        List<LedyUserClient> list = ledyUserClientService.selectLedyUserClientList(ledyUserClient);
        return getDataTable(list);
    }

    /**
     * 导出案件当事人列表
     */
    @PreAuthorize("@ss.hasPermi('erp:client:export')")
    @Log(title = "案件当事人", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, LedyUserClient ledyUserClient)
    {
        List<LedyUserClient> list = ledyUserClientService.selectLedyUserClientList(ledyUserClient);
        ExcelUtil<LedyUserClient> util = new ExcelUtil<LedyUserClient>(LedyUserClient.class);
        util.exportExcel(response, list, "案件当事人数据");
    }

    /**
     * 获取案件当事人详细信息
     */
    @PreAuthorize("@ss.hasPermi('erp:client:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(ledyUserClientService.selectLedyUserClientById(id));
    }

    /**
     * 新增案件当事人
     */
    @PreAuthorize("@ss.hasPermi('erp:client:add')")
    @Log(title = "案件当事人", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LedyUserClient ledyUserClient)
    {
        return toAjax(ledyUserClientService.insertLedyUserClient(ledyUserClient));
    }

    /**
     * 修改案件当事人
     */
    @PreAuthorize("@ss.hasPermi('erp:client:edit')")
    @Log(title = "案件当事人", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LedyUserClient ledyUserClient)
    {
        return toAjax(ledyUserClientService.updateLedyUserClient(ledyUserClient));
    }

    /**
     * 删除案件当事人
     */
    @PreAuthorize("@ss.hasPermi('erp:client:remove')")
    @Log(title = "案件当事人", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ledyUserClientService.deleteLedyUserClientByIds(ids));
    }
}
